const express = require("express");
const Router = express.Router();
const moment = require("moment");
const path = require("path");
const upload = require("./index.js");
const nowDate = moment().format("YYYY-MM-DD");
const ip = require("ip");
const IP = ip.address();




Router.use(express.static(path.join(__dirname,"../../public")));
// 上传单张图片的数据
Router.post("/goods", upload("goods").single("goods"), (req, res) => {
  let { filename } = req.file;
  res.send({
    status: 0,
    msg: "上传成功",
    path: `http://${IP}:3000/goods/${nowDate}/${filename}`,
  });
});

// 上传多张轮播图

Router.post("/goodsList", upload("goodsList").single("goodsList"), (req, res) => {
  let { filename } = req.file;
  res.send({
    status: 0,
    msg: "上传成功",
    path: `http://${IP}:3000/goodsList/${nowDate}/${filename}`,
  });
});















module.exports = Router;
